import request from '/@/utils/request';

/**查询数据*/
export function findAll() {
	return request({
		url: '/admin/routeConf/findAll',
		method: 'get',
	});
}
export const pageList = (params?: Object) => {
	return request({
		url: '/admin/routeConf/page',
		method: 'get',
		params,
	});
};


export function addOrUpdate(obj?: Object) {
	return request({
		url: '/admin/routeConf/update',
		method: 'post',
		data: obj,
	});
}
/**
 * 修改
 */
export function update(obj?: Object) {
	return request({
		url: '/admin/routeConf/update',
		method: 'put',
		data: obj,
	});
}

/**
 * 删除
 */
export function delObj(obj?: Object) {
	return request({
		url: '/admin/routeConf/delete',
		method: 'delete',
		data: obj,
	});
}
export function getObjDetails(obj?: object) {
	return request({
		url: '/admin/routeConf/details',
		method: 'get',
		params: obj,
	});
}
export function getObj(id?: string) {
	return request({
		url: '/admin/routeConf/findById' ,
		method: 'get',
		params: {id:id},
	});
}

export function validateRouteId(rule: any, value: any, callback: any, isEdit: boolean) {
	if (isEdit) {
		return callback();
	}

	getObjDetails({ routeId: value }).then((response) => {
		const result = response.data;
		if (result !== null) {
			callback(new Error('路由ID已经存在'));
		} else {
			callback();
		}
	});
}

export function validateRouteName(rule: any, value: any, callback: any, isEdit: boolean) {
	if (isEdit) {
		return callback();
	}

	getObjDetails({ name: value }).then((response) => {
		const result = response.data;
		if (result !== null) {
			callback(new Error('路由名称已经存在'));
		} else {
			callback();
		}
	});
}